﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KenLib.BusinessManager;
using DataInfo;
using System.Text.RegularExpressions;
using KenLib.Dal;
using System.Web.Services;

// Coder: Thanh Dong
// Date: 2012/04/05

public partial class JOINT_frmJ_CompBasicInput : System.Web.UI.Page
{

    事業内容Manager _事業内容Manager = new 事業内容Manager();
    基本情報Manager _基本情報Manager = new 基本情報Manager();
    /// <summary>
    /// Coder: Ha Van Hoat
    /// Xu ly khi trang duoc Load len
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {

        ((JOINT_MstPage_JOINT)this.Master).changeTitle("本社情報登録");
        ((JOINT_MstPage_JOINT)this.Master).HideLiArea("frmJ_CompBasicInput");

       

        //Xu ly viec load lai trang cho Role: 2
        if (Request.UrlReferrer != null)
        {
            string temp = Request.UrlReferrer != null ? Request.UrlReferrer.ToString() : "";
            if (temp != "" && (temp.IndexOf("frmJ_MCompManager.aspx") > -1 || temp.IndexOf("frmJ_JointCompBasicInfoRef.aspx") > -1))
            {
                Session.Remove("ddl_事業内容_Role_2"); //Session save datatable carrer VN TNS
                Session.Remove("本社情報_Role_2_InfoCheck"); //Session save datatable detal 企業 with 企業ID
            }
        }
        
        if (!IsPostBack)
        {

            if (Session["役"] == null || Session["役"].ToString() == "")
            {
                Response.Redirect("~/frmD_Login.aspx");
            }
            btn_戻る.Visible = false;
            btn_次.Visible = false;
            LoadingErrorMessge();
            LoadDataComboxbox();
            txt_企業名.Focus();
            if (Session["役"].ToString() == "3")
            {
                Response.Redirect("frmJ_MCompManager.aspx");
            }
            if (Session["役"].ToString() == "2" && (Session["frmJ_JointCompBasicInfoRef_Mode"] == null || Session["frmJ_JointCompBasicInfoRef_Mode"].ToString() == ""))
            {
                Response.Redirect("frmJ_MCompManager.aspx");
            }
            // Mode update go from frmJ_MCompManager
            if (Session["frmJ_JointCompBasicInfoRef_Mode"] != null && Session["frmJ_JointCompBasicInfoRef_Mode"].ToString() == "1")
            {   
                Session["frmJ_CompBasicInput_Mode"] = "2"; //Mode update
                DataTable dt = select基本情報_Mode_Update_59_Hoat(Session["企業コード_2"].ToString());
                ShowDataWithDataTable(dt);
            }
            else
            {
                Session["frmJ_CompBasicInput_Mode"] = "1"; //Mode insert
            }

            if (Session["obj_joint_59"] != null && Session["obj_joint_59"].ToString()!="")
            {
                本社情報 obj = (本社情報)Session["obj_joint_59"];

                txt_企業名.Text = ConvertHTMLtoText(obj.企業名);
                txt_企業名フリガナ.Text = ConvertHTMLtoText(obj.企業名フリガナ);
                txt_企業名省略名称.Text = ConvertHTMLtoText(obj.企業名省略名称);
                txt_住所.Text = ConvertHTMLtoText(obj.住所);

                string[] tel;
                tel = obj.ＴＥＬ.Split('-');
                txt_ＴＥＬ1.Text = tel[0]; txt_ＴＥＬ2.Text = tel[1]; txt_ＴＥＬ3.Text = tel[2];

                string[] fax;
                fax = obj.FAX.Split('-');
                txt_FAX1.Text = fax[0]; txt_FAX2.Text = fax[1]; txt_FAX3.Text = fax[2];

                txt_設立年月日.Text = obj.設立年月日.ToString().Substring(0, 10);
                txt_資本金.Text = obj.資本金1.ToString();
                txt_業種分類.Text = ConvertHTMLtoText(obj.業種分類);

                string temp = obj.事業内容.ToString();
                if (temp != "")
                {
                    ListItem lst = ddl_事業内容.Items.FindByValue(temp);
                    ddl_事業内容.SelectedIndex = ddl_事業内容.Items.IndexOf(lst);
                }

                if (!string.IsNullOrEmpty(obj.事業内容その他))
                {
                    ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript: CheckExists(); ", true);
                    txt_事業内容その他.Text = obj.事業内容その他;
                }


                txt_主要製品.Text = ConvertHTMLtoText(obj.主要製品.ToString());
                txt_主要貿易取引相手国輸出先.Text = ConvertHTMLtoText(obj.主要貿易取引相手国輸出先);
                txt_主要貿易取引相手国輸入先.Text = ConvertHTMLtoText(obj.主要貿易取引相手国輸入先);
                txt_ウェブサイト.Text = ConvertHTMLtoText(obj.ウェブサイト);
                txt_外国の推薦機関.Text = ConvertHTMLtoText(obj.外国の推薦機関);

            }
        }
    }

    /// <summary>
    /// Load thong diep loi vao cac control bat loi
    /// </summary>
    protected void LoadingErrorMessge()
    {
        RequiredFieldValidator1.ErrorMessage =  GetError("ER00001");
        RequiredFieldValidator2.ErrorMessage =  GetError("ER00001");
        //RequiredFieldValidator3.ErrorMessage = "ＴＥＬ" + GetError("ER00001");
        Regulartxt_ＴＥＬ1.ErrorMessage =  GetError("ER00002");
        Regulartxt_ＴＥＬ2.ErrorMessage =  GetError("ER00002");
        Regulartxt_ＴＥＬ3.ErrorMessage =  GetError("ER00002");
        validatetxt_ＴＥＬ1.ErrorMessage =  GetError("ER00001");
        validatetxt_ＴＥＬ2.ErrorMessage =  GetError("ER00001");
        validatetxt_ＴＥＬ3.ErrorMessage =  GetError("ER00001");
        //--------------------------------------------
        //--RequiredFieldValidator4.ErrorMessage = "FAX" + GetError("ER00001");
        validatetxt_FAX1.ErrorMessage =  GetError("ER00001");
        validatetxt_FAX2.ErrorMessage =  GetError("ER00001");
        validatetxt_FAX3.ErrorMessage =  GetError("ER00001");
        Regulartxt_FAX1.ErrorMessage =  GetError("ER00002");
        Regulartxt_FAX2.ErrorMessage =  GetError("ER00002");
        Regulartxt_FAX3.ErrorMessage =  GetError("ER00002");
        //--------------------------------------------
        RequiredFieldValidator5.ErrorMessage =  GetError("ER00001");
        RequiredFieldValidator6.ErrorMessage =  GetError("ER00001");

        RequiredFieldValidator7.ErrorMessage =  GetError("ER00001");
        RequiredFieldValidator8.ErrorMessage =  GetError("ER00001");
        RequiredFieldValidator9.ErrorMessage =  GetError("ER00001");
        //.......................................................................
        //RequiredFieldValidator10.ErrorMessage = "ＴＥＬ" + GetError("ER00001");
        validatortxt_代表者１ＴＥＬ1.ErrorMessage =  GetError("ER00001");
        validatortxt_代表者１ＴＥＬ2.ErrorMessage =  GetError("ER00001");
        validatortxt_代表者１ＴＥＬ3.ErrorMessage =  GetError("ER00001");
        Regulartxt_代表者１ＴＥＬ1.ErrorMessage =  GetError("ER00002");
        Regulartxt_代表者１ＴＥＬ2.ErrorMessage =  GetError("ER00002");
        Regulartxt_代表者１ＴＥＬ3.ErrorMessage =  GetError("ER00002");
        //----------------------------------------------------------
        RequiredFieldValidator11.ErrorMessage =  GetError("ER00001");
        //RequiredFieldValidator12.ErrorMessage = "氏名" + GetError("ER00001");
        //RequiredFieldValidator13.ErrorMessage = "フリガナ" + GetError("ER00001");
        //RequiredFieldValidator14.ErrorMessage = "役職" + GetError("ER00001");
        //------------------------------------------------------------
        //RequiredFieldValidator15.ErrorMessage = "ＴＥＬ" + GetError("ER00001");
        //validatortxt_代表者２ＴＥＬ1.ErrorMessage = "ＴＥＬ" + GetError("ER00001");
        //validatortxt_代表者２ＴＥＬ2.ErrorMessage = "ＴＥＬ" + GetError("ER00001");
        //validatortxt_代表者２ＴＥＬ3.ErrorMessage = "ＴＥＬ" + GetError("ER00001");
        //Regulartxt_代表者２ＴＥＬ1.ErrorMessage = "ＴＥＬ" + GetError("ER00002");
        //Regulartxt_代表者２ＴＥＬ2.ErrorMessage = "ＴＥＬ" + GetError("ER00002");
        //Regulartxt_代表者２ＴＥＬ3.ErrorMessage = "ＴＥＬ" + GetError("ER00002");
        //--------------------------------------------
        //RequiredFieldValidator16.ErrorMessage = "就任年月日" + GetError("ER00001");
        RequiredFieldValidator17.ErrorMessage =  GetError("ER00001");
        RequiredFieldValidator18.ErrorMessage =  GetError("ER00001");
        RequiredFieldValidator19.ErrorMessage =  GetError("ER00001");
        RequiredFieldValidator20.ErrorMessage =  GetError("ER00001");
        //RequiredFieldValidator21.ErrorMessage = "直通ＴＥＬ" + GetError("ER00001");
        validatortxt_担当１直通ＴＥＬ1.ErrorMessage =  GetError("ER00001");
        validatortxt_担当１直通ＴＥＬ2.ErrorMessage =  GetError("ER00001");
        validatortxt_担当１直通ＴＥＬ3.ErrorMessage =  GetError("ER00001");
        Regulartxt_担当１直通ＴＥＬ3.ErrorMessage =  GetError("ER00002");
        Regulartxt_担当１直通ＴＥＬ2.ErrorMessage =  GetError("ER00002");
        Regulartxt_担当１直通ＴＥＬ1.ErrorMessage =  GetError("ER00002");
        //--------------------------------------------------------- 
        RequiredFieldValidator22.ErrorMessage =  GetError("ER00001");
        //RequiredFieldValidator23.ErrorMessage = "社員" + GetError("ER00001");
        //RequiredFieldValidator24.ErrorMessage = "氏名" + GetError("ER00001");
        //RequiredFieldValidator25.ErrorMessage = "部署名" + GetError("ER00001");
        //RequiredFieldValidator26.ErrorMessage = "役職" + GetError("ER00001");
        //RequiredFieldValidator27.ErrorMessage = "担当２メールアドレス" + GetError("ER00001");直通ＴＥＬ就任年月日validatortxt_担当２直通ＴＥＬ1
        //validatortxt_担当２直通ＴＥＬ1.ErrorMessage = "直通ＴＥＬ" + GetError("ER00001");
        //validatortxt_担当２直通ＴＥＬ2.ErrorMessage = "直通ＴＥＬ" + GetError("ER00001");
        //validatortxt_担当２直通ＴＥＬ3.ErrorMessage = "直通ＴＥＬ" + GetError("ER00001");
        //RequiredFieldValidator28.ErrorMessage = "就任年月日" + GetError("ER00001");
        RequiredFieldValidator29.ErrorMessage =  GetError("ER00001");

        RegularExpressionValidator1.ErrorMessage = GetError("ER00002");
        RegularExpressionValidator2.ErrorMessage = GetError("ER00002");
        RegularExpressionValidator3.ErrorMessage = GetError("ER00002");
        RegularExpressionValidator4.ErrorMessage = GetError("ER00002");
        RegularExpressionValidator5.ErrorMessage = GetError("ER00002");

        CustomValidator1.ErrorMessage = GetError("ER00005");
        CustomValidator2.ErrorMessage = GetError("ER00005");
        CustomValidator3.ErrorMessage = GetError("ER00005");
        CustomValidator4.ErrorMessage = GetError("ER00005");
        CustomValidator5.ErrorMessage = GetError("ER00005");
        //RegularExpressionValidator6.ErrorMessage = GetError("ER00002");

        //---------------------携帯ＴＥＬ
        //Regulartxt_代表者２携帯ＴＥＬ1.ErrorMessage = "携帯ＴＥＬ" + GetError("ER00002");
        //Regulartxt_代表者２携帯ＴＥＬ2.ErrorMessage = "携帯ＴＥＬ" + GetError("ER00002");
        //Regulartxt_代表者２携帯ＴＥＬ3.ErrorMessage = "携帯ＴＥＬ" + GetError("ER00002");
        Regulartxt_担当１携帯ＴＥＬ1.ErrorMessage =  GetError("ER00002");
        Regulartxt_担当１携帯ＴＥＬ2.ErrorMessage =  GetError("ER00002");
        Regulartxt_担当１携帯ＴＥＬ3.ErrorMessage = GetError("ER00002");
        //Regulartxt_担当２携帯ＴＥＬ1.ErrorMessage = "携帯ＴＥＬ" + GetError("ER00002");
        //Regulartxt_担当２携帯ＴＥＬ2.ErrorMessage = "携帯ＴＥＬ" + GetError("ER00002");
        //Regulartxt_担当２携帯ＴＥＬ3.ErrorMessage = "携帯ＴＥＬ" + GetError("ER00002");
        //Regulartxt_担当２直通ＴＥＬ1.ErrorMessage = "携帯ＴＥＬ" + GetError("ER00002");
        //Regulartxt_担当２直通ＴＥＬ2.ErrorMessage = "携帯ＴＥＬ" + GetError("ER00002");
        //Regulartxt_担当２直通ＴＥＬ3.ErrorMessage = "携帯ＴＥＬ" + GetError("ER00002");
        RegularExpressionValidatorEmail1.ErrorMessage = GetError("ER00002");
        RegularExpressionValidatorEmail2.ErrorMessage = GetError("ER00002");
        RegularExpressionValidator6URL.ErrorMessage =  GetError("ER00002");
        RequiredFieldValidator3.ErrorMessage =  GetError("ER00001");
        customCheckName.ErrorMessage =  GetError("ER00009");
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Button 戻る click
    /// Status: Not use
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_戻る_Click(object sender, EventArgs e)
    {
        //if (Session["mode_31"]!=null && Session["mode_31"].ToString() == "1")
        //    Response.Redirect("frmJ_MCompManager.aspx");
        //else if (Session["mode_31"].ToString() == "2")
        //    Response.Redirect("frmJ_JointCompBasicInfoRef.aspx");
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Button 次 click 
    /// Status: Not use
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_次_Click(object sender, EventArgs e)
    {
        //Response.Redirect("frmJ_CompHistoryInput.aspx");
    }

    /// <summary>
    /// Lay ra ma loi tu CSDL
    /// </summary>
    /// <param name="errorid"></param>
    /// <returns></returns>
    public String GetError(string errorid)
    {
        Error er = new Error();
        er.ErrorID = errorid;
        ErrorManager frm_error = new ErrorManager();
        DataTable dt = frm_error.getError(er);
        return dt.Rows[0][2].ToString();
    }

    /// <summary>
    /// Kiem tra dinh dang ngay thang co hop le hay ko?
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    protected Boolean checkDateValid(String input)
    {
        String pattern = @"^(?ni:(?=\d)((?'year'((1[6-9])|([2-9]\d))\d\d)(?'sep'[/.-])(?'month'0?[1-9]|1[012])\2(?'day'((?<!(\2((0?[2469])|11)\2))31)|(?<!\2(0?2)\2)(29|30)|((?<=((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(16|[2468][048]|[3579][26])00)\2\3\2)29)|((0?[1-9])|(1\d)|(2[0-8])))(?:(?=\x20\d)\x20|$))?((?<time>((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2}))?)$";
        return Regex.IsMatch(input, pattern);
    }

    /// <summary>
    /// Default: When redirect to page not param is INSERT submit, else Update submit
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_登録_Click(object sender, EventArgs e)
    {
        DataTable dt_事業内容 = frmJ_IntroCompBasicInput_Select(Convert.ToInt32(ddl_事業内容.SelectedValue));
        if (dt_事業内容.Rows.Count > 0)
        {
            if (dt_事業内容.Rows[0]["種類コード"].ToString() == "0")
            {
                if (txt_事業内容その他.Text == "")
                {
                    RequiredFieldValidator3.IsValid = false;
                }
                else
                {
                    RequiredFieldValidator3.IsValid = true;
                }
            }
            else
            {
                RequiredFieldValidator3.IsValid = true;
            }

        }

        try
        {
            string temp = ddl_事業内容.SelectedValue.ToString();
            if (temp != "")
            {
                ListItem lst = ddl_事業内容.Items.FindByValue(temp);
                Session["ddl_事業内容_JS"] = lst.Text.ToString();
            }
            else
            {
                Session["ddl_事業内容_JS"] = "";
            }
            本社情報 _本社情報 = new 本社情報();
            if (Session["frmJ_CompBasicInput_Mode"].ToString()=="2") //Mode update
            {
                if (Page.IsValid == true)
                {
                    _本社情報 = Get本社情報();
                    _本社情報.企業ID = Int32.Parse(Session["企業コード_2"].ToString());
                   
                }
            }
            else if (Session["frmJ_CompBasicInput_Mode"].ToString() == "1")
            {
                _本社情報 = Get本社情報();   
            }
            Session["obj_joint_59"] = (本社情報)_本社情報;
            Response.Redirect("frmJ_CompBasicInputCheck.aspx");
        }
        catch (Exception ex)
        {

        }
    }

    /// <summary>
    /// Chuyen chuoi sang ma HTML
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    public string ConvertTexttoHTML(string temp)
    {
        temp = temp.Replace("<", "&lt;");
        temp = temp.Replace(">", "&gt;");
        return temp;
    }

    /// <summary>
    /// Chuyen ma HTML sang chuoi van ban
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    public string ConvertHTMLtoText(string temp)
    {
        temp = temp.Replace("&lt;", "<");
        temp = temp.Replace("&gt;", ">");
        temp = temp.Replace(Convert.ToString((char)13), "<br/>");
        return temp;
    }

    /// <summary>
    /// Do du lieu vao ComboBox
    /// </summary>
    /// <param name="mode"></param>
    protected void LoadDataComboxbox()
    {
        DataTable dt = new DataTable();
        dt = _事業内容Manager.select事業内容ColumnPartial_59(3);
        if (dt.Rows.Count > 0)
        {
            ddl_事業内容.DataSource = dt;
            ddl_事業内容.DataTextField = "事業内容";
            ddl_事業内容.DataValueField = "ID";
            ddl_事業内容.DataBind();
            ddl_事業内容.Items.Insert(0, new ListItem("[選択]", "-1"));
        }
    }

    protected void btn_リセット_Click(object sender, EventArgs e)
    {
        ClearTextPage();
        txt_企業名.Focus();
        if (Session["frmJ_JointCompBasicInfoRef_Mode"] != null && Session["frmJ_JointCompBasicInfoRef_Mode"].ToString() == "1")
        {
            LoadDataComboxbox();
            DataTable dt = select基本情報_Mode_Update_59_Hoat(Session["企業コード_2"].ToString());
            ShowDataWithDataTable(dt);
        }
        
    }

    /// <summary>
    /// Clear text for page
    /// </summary>
    private void ClearTextPage()
    {
        txt_企業名.Text = "";
        txt_企業名フリガナ.Text = "";
        txt_企業名省略名称.Text = "";
        txt_住所.Text = "";
        txt_ＴＥＬ1.Text = "";
        txt_ＴＥＬ2.Text = "";
        txt_ＴＥＬ3.Text = "";
        txt_FAX1.Text = "";
        txt_FAX2.Text = "";
        txt_FAX3.Text = "";
        txt_設立年月日.Text = "";
        txt_資本金.Text = "";
        txt_業種分類.Text = "";
        ddl_事業内容.SelectedIndex = 0;
        txt_主要製品.Text = "";
        txt_主要貿易取引相手国輸出先.Text = "";
        txt_主要貿易取引相手国輸入先.Text = "";
        //2.
        ddl_代表者１社員.SelectedIndex = 0;
        txt_代表者１氏名.Text = "";
        txt_代表者１氏名フリガナ.Text = "";
        ddl_代表者１役職.SelectedIndex = 0;
        txt_代表者１ＴＥＬ1.Text = "";
        txt_代表者１ＴＥＬ2.Text = "";
        txt_代表者１ＴＥＬ3.Text = "";
        txt_代表者１就任年月日.Text = "";

        //2.ddl_代表者2社員
        ddl_代表者2社員.SelectedIndex = 0;
        txt_代表者２氏名.Text = "";
        txt_代表者２氏名フリガナ.Text = "";
        ddl_代表者２役職.SelectedIndex = 0;
        txt_代表者２ＴＥＬ1.Text = "";
        txt_代表者２ＴＥＬ2.Text = "";
        txt_代表者２ＴＥＬ3.Text = "";
        txt_代表者２携帯ＴＥＬ1.Text = "";
        txt_代表者２携帯ＴＥＬ2.Text = "";
        txt_代表者２携帯ＴＥＬ3.Text = "";
        txt_代表者２就任年月日.Text = "";
        //-------------------------------------------3--------------------.
        ddl_担当１社員ID.SelectedIndex = 0;
        txt_担当１氏名.Text = "";
        txt_担当１部署名.Text = "";
        ddl_担当１役職.SelectedIndex = 0;
        txt_担当１メールアドレス.Text = "";
        txt_担当１直通ＴＥＬ1.Text = "";
        txt_担当１直通ＴＥＬ2.Text = "";
        txt_担当１直通ＴＥＬ3.Text = "";
        txt_担当１携帯ＴＥＬ1.Text = "";
        txt_担当１携帯ＴＥＬ2.Text = "";
        txt_担当１携帯ＴＥＬ3.Text = "";
        txt_担当１就任年月日.Text = "";
        txt_担当１コメント.Text = "";

        //......................4...........................................
        ddl_担当２社員ID.SelectedIndex = 0;
        txt_担当２氏名.Text = "";
        txt_担当２部署名.Text = "";
        ddl_担当２役職.SelectedIndex = 0;
        txt_担当２メールアドレス.Text = "";
        txt_担当２直通ＴＥＬ1.Text = "";
        txt_担当２直通ＴＥＬ2.Text = "";
        txt_担当２直通ＴＥＬ3.Text = "";
        txt_担当２携帯ＴＥＬ1.Text = "";
        txt_担当２携帯ＴＥＬ2.Text = "";
        txt_担当２携帯ＴＥＬ3.Text = "";
        txt_担当２就任年月日.Text = "";
        txt_担当２コメント.Text = "";

        //..........................5.....................
        txt_ウェブサイト.Text = "";
        txt_外国の推薦機関.Text = "";
    }

    /// <summary>
    /// Hien thi du lieu vao cac control neu la mode Update
    /// </summary>
    /// <param name="Id"></param>
    private void ShowDataWithDataTable(DataTable dt)
    {
       
        if (dt.Rows.Count > 0)
        {
            txt_企業名.Text = ConvertHTMLtoText(dt.Rows[0]["企業名"].ToString());
            txt_企業名フリガナ.Text = ConvertHTMLtoText(dt.Rows[0]["企業名フリガナ"].ToString());
            txt_企業名省略名称.Text = ConvertHTMLtoText(dt.Rows[0]["企業名省略名称"].ToString());
            txt_住所.Text = ConvertHTMLtoText(dt.Rows[0]["住所"].ToString());

            string tel = dt.Rows[0]["ＴＥＬ"].ToString();
            string[] tels = tel.Split('-');
            txt_ＴＥＬ1.Text = tels[0]; 
            txt_ＴＥＬ2.Text = tels[1]; 
            txt_ＴＥＬ3.Text = tels[2];

            string fax = dt.Rows[0]["FAX"].ToString();
            string[] faxs = fax.Split('-');
            txt_FAX1.Text = faxs[0]; 
            txt_FAX2.Text = faxs[1]; 
            txt_FAX3.Text = faxs[2];
            txt_設立年月日.Text = dt.Rows[0]["設立年月日"].ToString().Substring(0, 10);

            //double money = double.Parse(dt.Rows[0]["資本金"].ToString());
            string strMoney = dt.Rows[0]["資本金"].ToString();//Money VND
            if (strMoney != "")
            {
                strMoney= strMoney.Replace(".00", "");
                txt_資本金.Text = strMoney;
            }

            txt_業種分類.Text = ConvertHTMLtoText(dt.Rows[0]["業種分類"].ToString());

            string temp = "";
            temp = dt.Rows[0]["事業内容ID"].ToString();
            if (temp != "")
            {
                ListItem lst = ddl_事業内容.Items.FindByValue(temp);
                ddl_事業内容.SelectedIndex = ddl_事業内容.Items.IndexOf(lst);
                DataTable dt_事業内容 = frmJ_IntroCompBasicInput_Select(Convert.ToInt32(ddl_事業内容.SelectedValue));
                if (dt_事業内容.Rows.Count > 0)
                {                       
                    if (dt_事業内容.Rows[0]["種類コード"].ToString() == "0" && dt.Rows[0]["事業内容その他"].ToString() == "")
                    {
                        ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript: CheckExists(); ", true);
                    }
                }
               
            }

            temp = dt.Rows[0]["事業内容その他"].ToString();
            if (temp != "")
            {
                ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript: CheckExists(); ", true);
                txt_事業内容その他.Text = temp;
            }

            txt_主要製品.Text = ConvertHTMLtoText(dt.Rows[0]["主要製品"].ToString());
            txt_主要貿易取引相手国輸出先.Text = ConvertHTMLtoText(dt.Rows[0]["主要貿易取引相手国輸出先"].ToString());
            txt_主要貿易取引相手国輸入先.Text = ConvertHTMLtoText(dt.Rows[0]["主要貿易取引相手国輸入先"].ToString());
            //txt_代表者１氏名.Text = ConvertHTMLtoText(dt.Rows[0]["代表者１氏名"].ToString());
            //txt_代表者１氏名フリガナ.Text = ConvertHTMLtoText(dt.Rows[0]["代表者１氏名フリガナ"].ToString());

            //temp = dt.Rows[0]["代表者１役職"].ToString();
            //if (temp != "")
            //{
            //    ListItem lst = ddl_代表者１役職.Items.FindByText(temp);
            //    ddl_代表者１役職.SelectedIndex = ddl_代表者１役職.Items.IndexOf(lst);
            //}
            //tel = dt.Rows[0]["代表者１ＴＥＬ"].ToString();
            //tels = tel.Split('-');
            //txt_代表者１ＴＥＬ1.Text = tels[0]; txt_代表者１ＴＥＬ2.Text = tels[1]; txt_代表者１ＴＥＬ3.Text = tels[2];

            //txt_代表者１就任年月日.Text = dt.Rows[0]["代表者１就任年月日"].ToString();
            //txt_代表者２氏名.Text = ConvertHTMLtoText(dt.Rows[0]["代表者２氏名"].ToString());
            //txt_代表者２氏名フリガナ.Text = ConvertHTMLtoText(dt.Rows[0]["代表者２氏名フリガナ"].ToString());
            //temp = dt.Rows[0]["代表者２役職"].ToString();
            //if (temp != "")
            //{
            //    ListItem lst = ddl_代表者２役職.Items.FindByText(temp);
            //    ddl_代表者２役職.SelectedIndex = ddl_代表者２役職.Items.IndexOf(lst);
            //}
            //tel = dt.Rows[0]["代表者２ＴＥＬ"].ToString();
            //tels = tel.Split('-');
            //txt_代表者２ＴＥＬ1.Text = tels[0]; txt_代表者２ＴＥＬ2.Text = tels[1]; txt_代表者２ＴＥＬ3.Text = tels[2];

            //tel = dt.Rows[0]["代表者２携帯ＴＥＬ"].ToString();
            //tels = tel.Split('-');
            //txt_代表者２ＴＥＬ1.Text = tels[0]; txt_代表者２ＴＥＬ2.Text = tels[1]; txt_代表者２ＴＥＬ3.Text = tels[2];

            //txt_代表者２就任年月日.Text = dt.Rows[0]["代表者２就任年月日"].ToString();
            //txt_担当１氏名.Text = ConvertHTMLtoText(dt.Rows[0]["担当１氏名"].ToString());
            //txt_担当１部署名.Text = ConvertHTMLtoText(dt.Rows[0]["担当１部署名"].ToString());
            //temp = dt.Rows[0]["担当１役職"].ToString();
            //if (temp != "")
            //{
            //    ListItem lst = ddl_担当１役職.Items.FindByText(temp);
            //    ddl_担当１役職.SelectedIndex = ddl_担当１役職.Items.IndexOf(lst);
            //}

            //txt_担当１メールアドレス.Text = ConvertHTMLtoText(dt.Rows[0]["担当１メールアドレス"].ToString());
            //tel = dt.Rows[0]["担当１直通ＴＥＬ"].ToString();
            //tels = tel.Split('-');
            //txt_担当１直通ＴＥＬ1.Text = tels[0]; txt_担当１直通ＴＥＬ2.Text = tels[1]; txt_担当１直通ＴＥＬ3.Text = tels[2];

            //tel = dt.Rows[0]["担当１携帯ＴＥＬ"].ToString();
            //tels = tel.Split('-');
            //txt_担当１携帯ＴＥＬ1.Text = tels[0]; txt_担当１携帯ＴＥＬ2.Text = tels[1]; txt_担当１携帯ＴＥＬ3.Text = tels[2];
            //txt_担当１就任年月日.Text = dt.Rows[0]["担当１就任年月日"].ToString();
            //txt_担当１コメント.Text = ConvertHTMLtoText(dt.Rows[0]["担当１コメント"].ToString());
            //txt_担当２氏名.Text = ConvertHTMLtoText(dt.Rows[0]["担当２氏名"].ToString());
            //txt_担当２部署名.Text = ConvertHTMLtoText(dt.Rows[0]["担当２部署名"].ToString());
            //temp = dt.Rows[0]["担当２役職"].ToString();
            //if (temp != "")
            //{
            //    ListItem lst = ddl_担当２役職.Items.FindByText(temp);
            //    ddl_担当２役職.SelectedIndex = ddl_担当２役職.Items.IndexOf(lst);
            //}

            //txt_担当２メールアドレス.Text = ConvertHTMLtoText(dt.Rows[0]["担当２メールアドレス"].ToString());
            //tel = dt.Rows[0]["担当２直通ＴＥＬ"].ToString();
            //tels = tel.Split('-');
            //txt_担当２直通ＴＥＬ1.Text = tels[0]; txt_担当２直通ＴＥＬ2.Text = tels[1]; txt_担当２直通ＴＥＬ3.Text = tels[2];
            //tel = dt.Rows[0]["担当２携帯ＴＥＬ"].ToString();
            //tels = tel.Split('-');
            //txt_担当２携帯ＴＥＬ1.Text = tels[0]; txt_担当２携帯ＴＥＬ2.Text = tels[1]; txt_担当２携帯ＴＥＬ3.Text = tels[2];
            //txt_担当２就任年月日.Text = dt.Rows[0]["担当２就任年月日"].ToString();
            //txt_担当２コメント.Text = ConvertHTMLtoText(dt.Rows[0]["担当２コメント"].ToString());
            txt_ウェブサイト.Text = ConvertHTMLtoText(dt.Rows[0]["ウェブサイト"].ToString());
            txt_外国の推薦機関.Text = ConvertHTMLtoText(dt.Rows[0]["外国の推薦機関"].ToString());
            //tel = dt.Rows[0]["代表者２携帯ＴＥＬ"].ToString();
            //tels = tel.Split('-');
            //txt_代表者２携帯ＴＥＬ1.Text = tels[0]; txt_代表者２携帯ＴＥＬ2.Text = tels[1]; txt_代表者２携帯ＴＥＬ3.Text = tels[2];
        }
    }

    protected void ddl_代表者１社員_SelectedIndexChanged1(object sender, EventArgs e)
    {
        string temp = ddl_代表者１社員.SelectedValue.ToString();
        if (temp != "-1")
        { ListItem lst = ddl_代表者１社員.Items.FindByValue(temp); txt_代表者１氏名.Text = lst.Text; }


    }

    protected void ddl_代表者2社員_SelectedIndexChanged(object sender, EventArgs e)
    {
        string temp = ddl_代表者2社員.SelectedValue.ToString();
        if (temp != "-1")
        { ListItem lst = ddl_代表者2社員.Items.FindByValue(temp); txt_代表者２氏名.Text = lst.Text; }
    }

    protected void ddl_担当１社員ID_SelectedIndexChanged(object sender, EventArgs e)
    {
        string temp = ddl_担当１社員ID.SelectedValue.ToString();
        if (temp != "-1")
        { ListItem lst = ddl_担当１社員ID.Items.FindByValue(temp); txt_担当１氏名.Text = lst.Text; }
    }

    protected void ddl_担当２社員ID_SelectedIndexChanged(object sender, EventArgs e)
    {
        string temp = ddl_担当２社員ID.SelectedValue.ToString();
        if (temp != "-1")
        { ListItem lst = ddl_担当２社員ID.Items.FindByValue(temp); txt_担当２氏名.Text = lst.Text; }

    }

    /// <summary>
    /// Xu ly ket qua tra ve
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    [WebMethod]
    public static string IsCheckExist1(string value)
    {
        DataTable dt_事業内容 = new 事業内容Manager().frmJ_IntroCompBasicInput_Select(Convert.ToInt32(value));
        string result = "";
        if (dt_事業内容.Rows.Count > 0)
        {
            result = dt_事業内容.Rows[0]["種類コード"].ToString();
        }
        return result;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Get information detal table 事業内容
    /// </summary>
    /// <param name="ID"></param>
    /// <returns></returns>
    protected DataTable frmJ_IntroCompBasicInput_Select(int ID)
    {
        return _事業内容Manager.frmJ_IntroCompBasicInput_Select(ID);
    }

    /// <summary>
    /// Xoa day phay khoi so
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    protected string splitInt32(string value)
    {
        if (value == "" || value.Trim().Length < 0)
            return "";
        if (value.IndexOf(",") > -1)
        {
            string result = "";

            result = value.Replace(",", "");
            return result;
        }
        else
        {
            return value;
        }
    }

    /// <summary>
    /// Xu ly kiem tra trung ten cong ty phai cu
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="args"></param>
    protected void CheckName企業名(object sender, ServerValidateEventArgs args) 
    {
        
        string value = txt_企業名.Text.ToString();
        本社情報Manager manager = new 本社情報Manager();
        string frm_mode = Session["mode_31"] != null ? Session["mode_31"].ToString() : "";

        if (frm_mode == "1")
        {
            bool result = manager.checkSame企業名_59_31(value, 3);
            if (result == true)
            {
                args.IsValid = false;//Trung ten
                return;
            }
            else
            {
                args.IsValid = true;
            }
        }

        if (frm_mode == "2")
        {
            if (Session["役"].ToString() == "2")
            {
                string compcode = Session["企業コード_2"].ToString();
                string name_old = manager.select企業名_59_31(compcode);

                if (name_old.Equals(txt_企業名.Text.ToString()))
                {
                    args.IsValid = true;//Chua thay doi ten
                }
                else
                {
                    //Mode Update da thay doi ten, nen kiem tra xem co trung voi tat ca ten con lai
                    bool result = manager.checkSame企業名_59_31(value, 3);
                    if (result == true)
                    {
                        args.IsValid = false;//Trung ten
                        return;
                    }
                    else
                    {
                        args.IsValid = true;
                    }
                }

            }
            else
            { 
                //Role khac 2
                string compcode = Request.QueryString["p_id"].ToString();
                string name_old = manager.select企業名_59_31(compcode);

                if (name_old.Equals(txt_企業名.Text.ToString()))
                {
                    args.IsValid = true;//Chua thay doi ten
                }
                else
                {
                    //Mode Update da thay doi ten, nen kiem tra xem co trung voi tat ca ten con lai
                    bool result = manager.checkSame企業名_59_31(value, 3);
                    if (result == true)
                    {
                        args.IsValid = false;//Trung ten
                        return;
                    }
                    else
                    {
                        args.IsValid = true;
                    }
                }
                
            }
        }

    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Get object 本社情報
    /// Status: OK
    /// </summary>
    /// <returns></returns>
    protected 本社情報 Get本社情報()
    {
        本社情報 _本社情報 = new 本社情報();
        DataTable dt_事業内容 = frmJ_IntroCompBasicInput_Select(Convert.ToInt32(ddl_事業内容.SelectedValue));
        _本社情報.企業名 = ConvertTexttoHTML(txt_企業名.Text);
        _本社情報.企業名フリガナ = ConvertTexttoHTML(txt_企業名フリガナ.Text);
        _本社情報.企業名省略名称 = ConvertTexttoHTML(txt_企業名省略名称.Text);
        _本社情報.住所 = ConvertTexttoHTML(txt_住所.Text);
        _本社情報.ＴＥＬ = txt_ＴＥＬ1.Text + "-" + txt_ＴＥＬ2.Text + "-" + txt_ＴＥＬ3.Text;
        _本社情報.FAX = txt_FAX1.Text + "-" + txt_FAX2.Text + "-" + txt_FAX3.Text;
        _本社情報.設立年月日 = DateTime.Parse(txt_設立年月日.Text);
        _本社情報.資本金1 = Decimal.Parse(splitInt32(txt_資本金.Text));//
        _本社情報.業種分類 = ConvertTexttoHTML(txt_業種分類.Text);
        _本社情報.事業内容 = ddl_事業内容.SelectedValue.ToString();
       
        if (dt_事業内容.Rows.Count > 0)
        {
            if (dt_事業内容.Rows[0]["種類コード"].ToString() == "0")
            {
                _本社情報.事業内容その他 = txt_事業内容その他.Text;//////text area
            }
            else
            {
                _本社情報.事業内容その他 = "";
            }
        }
        _本社情報.主要製品 = ConvertTexttoHTML(txt_主要製品.Text);
        _本社情報.主要貿易取引相手国輸出先 = ConvertTexttoHTML(txt_主要貿易取引相手国輸出先.Text);
        _本社情報.主要貿易取引相手国輸入先 = ConvertTexttoHTML(txt_主要貿易取引相手国輸入先.Text);
        //_本社情報.代表者１氏名 = ConvertTexttoHTML(txt_代表者１氏名.Text);
        //_本社情報.代表者１氏名フリガナ = ConvertTexttoHTML(txt_代表者１氏名フリガナ.Text);
        //_本社情報.代表者１役職 = ddl_代表者１役職.SelectedValue.ToString();

        //_本社情報.代表者１ＴＥＬ = txt_代表者１ＴＥＬ1.Text + "-" + txt_代表者１ＴＥＬ2.Text + "-" + txt_代表者１ＴＥＬ3.Text;
        //_本社情報.代表者１就任年月日 = DateTime.Parse(txt_代表者１就任年月日.Text);
        //_本社情報.代表者２氏名 = ConvertTexttoHTML(txt_代表者２氏名.Text);
        //_本社情報.代表者２氏名フリガナ = ConvertTexttoHTML(txt_代表者２氏名フリガナ.Text);
        //_本社情報.代表者２役職 = ddl_代表者２役職.SelectedValue.ToString();

        //_本社情報.代表者２ＴＥＬ = txt_代表者２ＴＥＬ1.Text + "-" + txt_代表者２ＴＥＬ2.Text + "-" + txt_代表者２ＴＥＬ3.Text;

        //_本社情報.代表者２携帯ＴＥＬ = txt_代表者２携帯ＴＥＬ1.Text + "-" + txt_代表者２携帯ＴＥＬ2.Text + "-" + txt_代表者２携帯ＴＥＬ3.Text;//
        //if (txt_代表者２就任年月日.Text != "")
        //    _本社情報.代表者２就任年月日 = DateTime.Parse(txt_代表者２就任年月日.Text);
        //_本社情報.担当１氏名 = ConvertTexttoHTML(txt_担当１氏名.Text);
        //_本社情報.担当１部署名 = ConvertTexttoHTML(txt_担当１部署名.Text);
        //_本社情報.担当１役職 = ddl_担当１役職.SelectedValue.ToString();
        //_本社情報.担当１メールアドレス = ConvertTexttoHTML(txt_担当１メールアドレス.Text);

        //_本社情報.担当１直通ＴＥＬ = txt_担当１直通ＴＥＬ1.Text + "-" + txt_担当１直通ＴＥＬ2.Text + "-" + txt_担当１直通ＴＥＬ3.Text;

        //_本社情報.担当１携帯ＴＥＬ = txt_担当１携帯ＴＥＬ1.Text + "-" + txt_担当１携帯ＴＥＬ2.Text + "-" + txt_担当１携帯ＴＥＬ3.Text;

        //_本社情報.担当１就任年月日 = DateTime.Parse(txt_担当１就任年月日.Text);
        //_本社情報.担当１コメント = ConvertTexttoHTML(txt_担当１コメント.Text);
        //_本社情報.担当２氏名 = ConvertTexttoHTML(txt_担当２氏名.Text);
        //_本社情報.担当２部署名 = ConvertTexttoHTML(txt_担当２部署名.Text);
        //_本社情報.担当２役職 = ddl_担当２役職.SelectedValue.ToString();
        //_本社情報.担当２メールアドレス = ConvertTexttoHTML(txt_担当２メールアドレス.Text);

        //_本社情報.担当２直通ＴＥＬ = txt_担当２直通ＴＥＬ1.Text + "-" + txt_担当２直通ＴＥＬ2.Text + "-" + txt_担当２直通ＴＥＬ3.Text;

        //_本社情報.担当２携帯ＴＥＬ = txt_担当２携帯ＴＥＬ1.Text + "-" + txt_担当２携帯ＴＥＬ2.Text + "-" + txt_担当２携帯ＴＥＬ3.Text;
        //if (txt_担当２就任年月日.Text != "")
        //    _本社情報.担当２就任年月日 = DateTime.Parse(txt_担当２就任年月日.Text);
        //_本社情報.担当２コメント = ConvertTexttoHTML(txt_担当２コメント.Text);
        _本社情報.ウェブサイト = ConvertTexttoHTML(txt_ウェブサイト.Text);
        _本社情報.外国の推薦機関 = ConvertTexttoHTML(txt_外国の推薦機関.Text);
        return _本社情報;
    }

    protected DataTable select基本情報_Mode_Update_59_Hoat(string id)
    {
        return _基本情報Manager.select基本情報_Mode_Update_59_Hoat(id);
    }
}
